﻿namespace Web.Control.WWW.Files
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using Model.WWW_WWW.files;
    using BLF.WWW_WWW.Files;
    using System.Collections.Generic;
    using BLF;

    public class Default : BaseControl
    {
        
        protected int pageIndex = 1;
        /// <summary>
        /// 目标语言
        /// </summary>
        protected string Learn = "";
        /// <summary>
        /// 使用语言
        /// </summary>
        protected string BaseL = "";
        /// <summary>
        /// 排序1:CreateDate 2:TotalView 3:Likes 4:Commented
        /// </summary>
        protected int dt = 1;
        protected Repeater repFiles;
        protected Repeater repTags;
        protected Repeater rptLL;
        protected List<FileTagModel> tmList;
        protected List<FileDocModel> fdList;
        /// <summary>
        /// 数据数量
        /// </summary>
        protected int RecordCount = 0;
        protected override void OnLoad(EventArgs e)
        {

            if (Request.Cookies["italkiLearn"] == null && Request.Cookies["italkiSpeak"] == null)
            {
                HttpCookie llCookie = new HttpCookie("italkiLearn", "all");
                HttpCookie blCookie = new HttpCookie("italkiSpeak", "all");
                Response.Cookies.Add(llCookie);
                Response.Cookies.Add(blCookie);
            }
            if(!string.IsNullOrEmpty(Request["dt"]))
            {
                dt =int.Parse(Request["dt"].ToString());
            }
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    pageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out pageIndex);
                }
            }
            if (!string.IsNullOrEmpty(Request["ll"]) && Request["ll"] != "")
            {
                Learn = Request["ll"];
                HttpCookie llCookie = new HttpCookie("italkiLearn", Learn);
                Response.Cookies.Add(llCookie);
            }
            else
            {
                Learn = Request.Cookies["italkiLearn"].Value;
            }
            if (!string.IsNullOrEmpty(Request["bl"]) && Request["bl"] != "")
            {
                BaseL = Request["bl"];
                HttpCookie blCookie = new HttpCookie("italkiSpeak", BaseL);
                Response.Cookies.Add(blCookie);
            }
            else
            {
                BaseL = Request.Cookies["italkiSpeak"].Value;
            }
            fdList = Files.GetFilesDoc(Learn, BaseL, dt, pageIndex, 15, out tmList, out RecordCount);
            int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)15));
            if (pageIndex > pCount) pageIndex = pCount;
            if (repFiles != null)
            {
                repFiles.DataSource = fdList;
                repFiles.DataBind();
            }
            if (repTags != null)
            {
                repTags.DataSource = tmList;
                repTags.DataBind();
            }
            if (rptLL != null)
            {
                List<LanguageObj> lanObjList = new List<LanguageObj>();
                lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                rptLL.DataSource = lanObjList;
                rptLL.DataBind();
            }
            //标题
            if (Learn != "" && Learn.ToLower() != "all" && BaseL != "" && BaseL.ToLower() != "all")
            {
                this.DynamicTitle = GetText("SF503", new string[] { GetLanguageText(Learn), GetLanguageText(BaseL) });
                this.DynamicKeywords = GetText("SF504", new string[] { GetLanguageText(Learn), GetLanguageText(BaseL) });
                this.DynamicDescription = GetText("SF505", new string[] { GetLanguageText(Learn), GetLanguageText(BaseL) });
            }
            else {
                this.DynamicTitle = GetText("SF500");
                this.DynamicKeywords = GetText("SF501");
                this.DynamicDescription = GetText("SF502");
            }
            
            //Lx.Web.Common.UI.TDTPageBase thisPage = (Lx.Web.Common.UI.TDTPageBase)this.Page;
            //if (thisPage.metaTitle != null)
            //{
                
            //        thisPage.metaTitle.Text = GetText("AS500");
            //        thisPage.metaKey.Text = String.Format(thisPage.metaKey.Text, GetText("AS501"));
            //        thisPage.metaDes.Text = String.Format(thisPage.metaDes.Text, GetText("AS502"));
            //}
        }

    

    }
}